package ${package.Controller};

import com.baomidou.mybatisplus.core.metadata.IPage;
import ${package.Entity}.${entity};
import cn.eidos.blogs.openapi.rest.Resp;
import ${package.Service}.${table.serviceName};
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

<#if restControllerStyle>
<#else>
    import org.springframework.stereotype.Controller;
</#if>
<#if superControllerClassPackage??>
    import ${superControllerClassPackage};
</#if>

import java.util.List;

/**
* @author ： ${author}
* @date ：Created in ${date}
* @description：${table.comment!} Controller接口
* @modified By：
* @version: 1.0
*/
@Api(tags = "${table.comment}")
<#if restControllerStyle>
@RestController
<#else>
@Controller
</#if>
@RequestMapping("<#if package.ModuleName??>/${package.ModuleName}</#if><#if controllerMappingHyphenStyle??>${controllerMappingHyphen}<#else>${table.entityPath}</#if>")
<#if kotlin>
class ${table.controllerName}<#if superControllerClass??> : ${superControllerClass}()</#if>
<#else>
<#if superControllerClass??>
public class ${table.controllerName} extends ${superControllerClass} {
<#else>
public class ${table.controllerName} {
</#if>

    @Autowired
    private ${table.serviceName} ${table.serviceName?uncap_first};

    @ApiOperation(value = "${table.comment}分页列表")
    @ApiImplicitParams({
    @ApiImplicitParam(name = "pageNo", value = "页面", dataType = "Long"),
    @ApiImplicitParam(name = "pageSize", value = "页面数据量", dataType = "Long"),
    @ApiImplicitParam(name = "sort", value = "排序方式排序[true:正序; false:倒序]", dataType = "Boolean"),
    @ApiImplicitParam(name = "sortName", value = "排序字段,参照返回字段", dataType = "String")})
    @PostMapping(value = "/page.do")
    public  Resp<IPage<${entity}>> page(HttpServletRequest request , @RequestBody ${entity} param) {
        return Resp.success(${table.serviceName?uncap_first}.page(param));
    }

    @ApiOperation(value = "${table.comment}列表")
    @PostMapping(value = "/list.do")
    public  Resp<List<${entity}>> list(HttpServletRequest request , @RequestBody ${entity} param) {
        return Resp.success(${table.serviceName?uncap_first}.list(param));
    }

    @ApiOperation(value = "${table.comment}详情")
    @PostMapping(value = "/info/{id}")
    public  Resp<${entity}> info(@PathVariable Long id) {
        try {
            return Resp.success(${table.serviceName?uncap_first}.info(id));
        }catch (Exception e){
            e.printStackTrace();
            return Resp.failed();
        }
    }

    @ApiOperation(value = "${table.comment}新增")
    @PostMapping(value = "/add.do")
    public  Resp<Boolean> add(@RequestBody ${entity} param) {
        try {
            ${table.serviceName?uncap_first}.add(param);
            return Resp.success();
        }catch (Exception e){
            e.printStackTrace();
            return Resp.failed();
        }
    }

    @ApiOperation(value = "${table.comment}修改")
    @PostMapping(value = "/modify.do")
    public  Resp<Boolean> modify(@RequestBody ${entity} param) {
        try {
            ${table.serviceName?uncap_first}.modify(param);
            return Resp.success();
        }catch (Exception e){
            e.printStackTrace();
            return Resp.failed();
        }
    }

    @ApiOperation(value = "${table.comment}删除(单个条目)")
    @PostMapping(value = "/remove/{id}")
    public  Resp<Boolean> remove(@PathVariable Long id) {

        try {
            ${table.serviceName?uncap_first}.remove(id);
            return Resp.success();
        }catch (Exception e){
            e.printStackTrace();
            return Resp.failed();
        }
    }

    @ApiOperation(value = "${table.comment}删除(多个条目)")
    @PostMapping(value = "/removes.do")
    public  Resp<Boolean> removes( @RequestBody List<Long> ids) {
        try {
            ${table.serviceName?uncap_first}.removes(ids);
            return Resp.success();
        }catch (Exception e){
            e.printStackTrace();
            return Resp.failed();
        }
    }

}
</#if>